package com.bp.hearthealth.pulse.lnapps.bp_ui.bp_activity.bp_blood_pressure

import com.bp.hearthealth.pulse.lnapps.R
import com.bp.hearthealth.pulse.lnapps.bp_extension.UIHelperBp

enum class BpBloodPressureStatus {
    Hypotension, Normal, Elevated, Hypertension_Stage1, Hypertension_Stage2, Hypertensive_Crisis;

    companion object {
        fun mapToInt(status: BpBloodPressureStatus): Int {
            return when (status) {
                Hypotension -> 0
                Normal -> 1
                Elevated -> 2
                Hypertension_Stage1 -> 3
                Hypertension_Stage2 -> 4
                Hypertensive_Crisis -> 5
            }
        }

        fun mapToColor(status: BpBloodPressureStatus): Int {
            return when (status) {
                Hypotension -> UIHelperBp.getColor(R.color.color_027FFB)
                Normal -> UIHelperBp.getColor(R.color.color_2BBC8B)
                Elevated -> UIHelperBp.getColor(R.color.color_F9DB18)
                Hypertension_Stage1 -> UIHelperBp.getColor(R.color.color_FFB900)
                Hypertension_Stage2 -> UIHelperBp.getColor(R.color.color_FF9501)
                Hypertensive_Crisis -> UIHelperBp.getColor(R.color.color_F64A10)
            }
        }

        /**
         * type:
         *      0->0,1,2,3,4,5
         *      1->color
         */
        fun getBloodPressureStateOrColor(type: Int, systolic: Int, diastolic: Int): Int {
            return when {
                systolic < 90 || diastolic < 60 -> {
                    if (type == 0) {
                        mapToInt(Hypotension)
                    } else {
                        mapToColor(Hypotension)
                    }
                }

                systolic in 90..119 && diastolic in 60..79 -> {
                    if (type == 0) {
                        mapToInt(Normal)
                    } else {
                        mapToColor(Normal)
                    }
                }

                systolic in 120..129 && diastolic in 60..79 -> {
                    if (type == 0) {
                        mapToInt(Elevated)
                    } else {
                        mapToColor(Elevated)
                    }
                }

                (systolic in 130..139 || diastolic in 80..89) -> {
                    if (type == 0) {
                        mapToInt(Hypertension_Stage1)
                    } else {
                        mapToColor(Hypertension_Stage1)
                    }
                }

                (systolic in 140..180 || diastolic in 90..120) -> {
                    if (type == 0) {
                        mapToInt(Hypertension_Stage2)
                    } else {
                        mapToColor(Hypertension_Stage2)
                    }
                }

                else -> {
                    if (type == 0) {
                        mapToInt(Hypertensive_Crisis)
                    } else {
                        mapToColor(Hypertensive_Crisis)
                    }
                }
            }
        }
    }
}